<?php

namespace app\api\controller\v1;

use app\enterprise\model\TrainType;
use app\model\plan\PlanStaff;
use app\model\train\Train;
use app\Request;

class IndexController
{
    public function index(Request $request)
    {
        list($type) = $request->getMore([
            ['type', 1] ,
        ], true);
        $where[] = ['plan_staff.status' ,'=' , 1] ;
        if($type == 0){

            $where[] = ['start_time' , '<' , time()] ;
            $where[] = ['end_time' , '>' , time()] ;
            $where[] = ['complete_status' , '=' , 1] ;
        }
        if($type == 1){

            $where[] = ['complete_status' , '=' , 5] ;
        }
        if($type == 2){

            $where[] = ['complete_status' , '=' , 9] ;
        }
        if($type == 3){
            $where[] = ['complete_status' , '=' , 10] ;
//            $where[] = ['plan_staff.exam_status' , '=' , 1] ;
        }
//        if($type == 3){
//            $where[] = ['complete_status' , '=' , 19] ;
//        }
        $where[] = ['online_status' , '=' , 9] ;
        $where[] = ['staff_id' ,'=' , $request->staffId()] ;
        $list = PlanStaff::where($where)->alias('p1')
            ->withJoin('plan')
            ->field('plan_staff.id,plan_staff.complete_status,plan_id,progress')
            ->select()->each(function ($data){
            $data['time_status_str'] = '培训中'  ;
            $data['plan_name'] = $data->plan->plan_name ;
            $data['exam_ret'] = $data->plan->exam_id > 0 ? 1 : 0 ;
            $data['start_time'] = date('Y-m-d' , $data->plan->start_time)  ;
            $data['end_time'] = date('Y-m-d' , $data->plan->end_time)  ;
            $data['type'] = \app\model\basic\TrainType::getColumnName($data->plan->type_ids , 'title' , true);
            unset($data->plan) ;
        }) ;
        return app('json')->success([
                'list' => $list ,
                'img_url' => $request->domain() . '/upload/company/banner.jpg'
            ]);

    }
    public function about()
    {
        return app('json')->success(['info' => "关于我们"]);

    }
}